package com.contant;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import com.tunan.system.persistence.model.SpringContextUtil;

public class BirthcontroljsUtil {
	public static final String ALL_PEOPLE_MODEL_ID ="AllPeopleModel";
	public static final String PEOPLE_MODEL_ID = "peopleModel";
	public static final String W_PEOPLE_MODEL_ID ="WholePeopleModel";
	public static final String BIRTH_MODEL_ID = "birthcontroljsModel";
	public static final String PHOTO_MODEL_ID = "photoModel";
	public static final String WHOLE_PEOPLE_MODEL_ID ="WholePeopleModel";
	public static final String ALL_LDRY_MODEL_ID ="peoplebusinessModel";
	/**
	 * 计生model的Id
	 */
	public static final String BIRTHCONTROLJS_MODEL_ID ="birthcontroljsModel";
	/**
	 * 计生model的Id
	 */
	public static final String BIRTHCONTROLJS_PEOPLE_MODEL_ID = "birthcontroljsPeopleModel";
	/**
	 * 验证
	 */
	public static final String CHECKCHAIN ="byjszCheckChain";
	/**
	 * 人员详细查询Action
	 */
	public static final String PEOPLE_DETAILQUERY_ACTION_ID = "detailDjbPeopleQueryAction";
	
	/**
	 * 房屋可以被新增
	 */
	public static final String CAN_CREAT = "creat";
	/**
	 * 房屋可以被更新 
	 */
	public static final String CAN_UPDATE = "update";
	/**
	 * 房屋不可以被使用 
	 */
	public static final String CANNOT = "cannot";
	/**
	 * 无记录
	 */
	public static final String NORECORD = "noRecord";
	/**
	 * 成功
	 */
	public static final String SECUSS = "secuss";
	/**
	 * 失败
	 */
	public static final String ERROR = "error";
	
	/**
	 * 业务流水号:ywlsh
	 */
	public static final String P_YWLSH = "ywlsh";
	/**
	 * 街(路巷):jddm
	 */
	public static final String P_JDDM = "jddm";
	/**
	 * 门(楼)牌号:zhid
	 */
	public static final String P_ZHID = "zhid";

	/**
	 * 详址(房号):fhid
	 */
	public static final String P_FHID = "fhid";
	/**
	 * 人员Id:ryid
	 */
	public static final String P_RYID = "ryid";
	/**
	 * 姓名:xm
	 */
	public static final String P_XM = "xm";
	/**
	 * 证件号码:zjhm
	 */
	public static final String P_ZJHM = "zjhm";
	/**
	 * 户籍省:sheng
	 */
	public static final String P_SHENG = "sheng";
	/**
	 * 户籍市:shi
	 */
	public static final String P_SHI = "shi";
	/**
	 * 户籍县:xian
	 */
	public static final String P_XIAN = "xian";
	/**
	 * 配偶户籍省:posheng
	 */
	public static final String P_POSHENG = "posheng";
	/**
	 * 配偶户籍市:poshi
	 */
	public static final String P_POSHI = "poshi";
	/**
	 * 配偶户籍县:poxian
	 */
	public static final String P_POXIAN = "poxian";
	/**
	 * 户口性质:hkxz
	 */
	public static final String P_HKXZ = "hkxz";
	/**
	 * 来市日期:lsrq
	 */
	public static final String P_LSRQ = "lsrq";
	/**
	 * 门牌编号:mpbh
	 */
	public static final String P_MPBH = "mpbh";
	/**
	 * 联系电话:hjdh
	 */
	public static final String P_HJDH = "hjdh";
	/**
	 * 户籍地址:dz
	 */
	public static final String P_DZ = "dz";
	/**
	 * 注销时间:zxsj
	 */
	public static final String P_ZXSJ = "zxsj";
	/**
	 * 暂住地址详址:zzdzxz
	 */
	public static final String P_ZZDZXZ = "zzdzxz";
	/**
	 * 更新时间:updatetime
	 */
	public static final String P_UPDATETIME ="updatetime";
	/**
	 * 流动人员业务流水号:ldryywlsh
	 */
	public static final String P_LDRYYWLSH = "ldryywlsh";
	/**
	 * 配偶证件号码:pozjhm
	 */
	public static final String P_POZJHM = "pozjhm";
	/**
	 * 街(镇):jz
	 */
	public static final String P_JZ = "jz";
	/**
	 * 注销原因:zxyy
	 */
	public static final String P_ZXYY = "zxyy";

	
	///////////////////////  提示信息  //////////////////////
	/**
	 * 该人员已经登记过计生证信息了!
	 */
	public static final String M_PEOPLE_ALREADY_EXIST_IN_JS = "该人员已经登记过计生证信息了！";
	/**
	 * 更新计生证信息失败
	 */
	public static final String M_UPDATE_BIRTHCONTROLJS_ERROR = "更新计生证信息失败！";
	/**
	 * 没有对应计生信息,更新计生证信息失败
	 */
	public static final String M_NO_RECORD = "没有对应计生信息,更新计生证信息失败！";
	/**
	 * 房屋不可用
	 */
	public static final String M_HOUSE_CANNOT_BE_USERD = "房屋不可用！";
	
	private  static JdbcTemplate jt=SpringContextUtil.getApplicationContext().getBean(JdbcTemplate.class);;
	
	
	public static String getMpbh(String fhid) {
			String mpbh = "";
			if (fhid!=null || "".equals(fhid))
			{
				String sql = "select czwmph from t_gg_fwxxfh where fhid='"+fhid+"'";
				
				List list = jt.queryForList(sql);
				if (list!=null && list.size()>0)
				{
					mpbh = (String) ((Map)list.get(0)).get("CZWMPH");
				}
			}
			return mpbh;
	}
	
//	public static String getWgxx(String qybh) {
//			String dw = "";
//			if (qybh!=null || "".equals(qybh))
//			{
//				String sql = "select dwmc,dwdz  from t_gg_dwxx where qybh='"+qybh+"'";
//				List list = jt.queryForList(sql);
//				if (list!=null && list.size()>0)
//				{
//					String dwmc = (String) ((Map)list.get(0)).get("DWMC");
//					String dwdz = (String) ((Map)list.get(0)).get("DWDZ");
//					if(dwmc ==null || "".equals(dwmc)){
//						return "";
//					}else if (dwdz!=null || "".equals(dwdz)){
//						dw = checkValueLength(dw.concat(dwmc).concat(" ").concat(dwdz),40/2);
//					}
//					else{
//						dw=checkValueLength(dw.concat(dwmc),40/2);
//					}
//				}
//			}
//			return dw;
//	}
 
//
//	public static String checkValueLength(String v, int length)
//	{
//		String result;
//		if((v == null) || (v.equals("")))
//		{
//			result = "";
//		}
//		else
//		{
//			if(v.length() > length)
//			{
//				result = getSubstr(v, length * 2);
//			}
//			else
//			{
//				result = v;
//			}
//		}
//		return result;
//	}
	
//	private static String getSubstr(String s, int length)
//	{
//		String result = "";
//		char[] c = s.toCharArray();
//		CharRange cr = new CharRange('\u0000', '\u00FF');
//		int j = 0;
//		for(int i = 0; i < c.length; i++)
//		{
//			if(cr.contains(c[i]))
//			{
//				result += c[i];
//				j++;
//			}
//			else
//			{
//				if(j + 2 > length)
//				{
//					break;
//				}
//				result += c[i];
//				j += 2;
//			}
//			if(j >= length)
//			{
//				break;
//			}
//		}
//		return result;
//	}
	
//	/**
//	 * Function: 通过县截取省和市的信息。
//	 * 
//	 * @param models
//	 */
//	public void getShengAndShiFromXian(IGenericModel models) 
//	{
//		if (models.getValue().get(BirthcontroljsUtil.P_XIAN) != null
//				&& models.getValue().get(BirthcontroljsUtil.P_XIAN).getCode() != null)
//		{
//			models.getValue().put(BirthcontroljsUtil.P_SHENG,
//					new Value("", (models.getValue().get(BirthcontroljsUtil.P_XIAN).
//							getCode().toString()).substring(0, 2)));
//			models.getValue().put(BirthcontroljsUtil.P_SHI,
//					new Value("", (models.getValue().get(BirthcontroljsUtil.P_XIAN).
//							getCode().toString()).substring(0, 4)));
//		}
//	}
//	
//	/**
//	 * Function: 通过计生证关联人的配偶的县截取省和市的信息。
//	 * 
//	 * @param models
//	 */
//	public void getPoshengAndPoshiFromPoxian(IGenericModel models) 
//	{
//		if (models.getValue().get(BirthcontroljsUtil.P_POXIAN) != null
//				&& models.getValue().get(BirthcontroljsUtil.P_POXIAN).getCode() != null)
//		{
//			models.getValue().put(BirthcontroljsUtil.P_POSHENG,
//					new Value("", (models.getValue().get(BirthcontroljsUtil.P_POXIAN).
//							getCode().toString()).substring(0, 2)));
//			models.getValue().put(BirthcontroljsUtil.P_POSHI,
//					new Value("", (models.getValue().get(BirthcontroljsUtil.P_POXIAN).
//							getCode().toString()).substring(0, 4)));
//		}
//	}
	
	/**
	 * Functionn: 通过姓名和证件号码获得计生业务流水号lwlsh
	 * 
	 * @param cfg
	 * @param xm
	 * @param zjhm
	 * @return
	 */
	public String getBirthcontroljsYwlshByXmAndZjhm(String ryid)
	{
		String ywlsh = "";
		String sql = "select ywlsh from t_js_jsz where ryid=?";
		List<Map<String, Object>> rows = jt.query(sql, new Object[] { ryid }, new ColumnMapRowMapper());
		if ((rows != null && rows.size() > 0)) {
			ywlsh = rows.get(0).get("ywlsh").toString();
		}
		return ywlsh;

	}
}
